package com.woniuxy.controller;

import com.woniuxy.entity.ProductSpecRelations;
import com.woniuxy.service.ProductSpecRelationsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import com.woniuxy.utils.ResponseResult;


/**
 * (ProductSpecRelations)表控制层
 *
 * @author makejava
 * @since 2025-07-15 17:07:13
 */
@RestController
@RequestMapping("productSpecRelations")
public class ProductSpecRelationsController {
    /**
     * 服务对象
     */
    @Autowired
    private ProductSpecRelationsService productSpecRelationsService;
    /**
     * 通过option_id 和product_id 查询对应的规格增加价格
     */
    @GetMapping("/addprice/{option_id}")
    public ResponseResult<ProductSpecRelations> findByOptId(@PathVariable("option_id")Integer option_id) {
        return ResponseResult.success(productSpecRelationsService.findByOptId(option_id));
    }

    /**
     * 分页查询
     *
     * @param productSpecRelations 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @GetMapping
    public ResponseEntity<Page<ProductSpecRelations>> queryByPage(ProductSpecRelations productSpecRelations, PageRequest pageRequest) {
        return ResponseEntity.ok(this.productSpecRelationsService.queryByPage(productSpecRelations, pageRequest));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public ResponseEntity<ProductSpecRelations> queryById(@PathVariable("id") Integer product_id) {
        return ResponseEntity.ok(this.productSpecRelationsService.queryById(product_id));
    }

    /**
     * 新增数据
     *
     * @param productSpecRelations 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<ProductSpecRelations> add(ProductSpecRelations productSpecRelations) {
        return ResponseEntity.ok(this.productSpecRelationsService.insert(productSpecRelations));
    }

    /**
     * 编辑数据
     *
     * @param productSpecRelations 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<ProductSpecRelations> edit(ProductSpecRelations productSpecRelations) {
        return ResponseEntity.ok(this.productSpecRelationsService.update(productSpecRelations));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.productSpecRelationsService.deleteById(id));
    }

}

